import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

/**
 * 
 */

/**
 * @author haui
 *
 */
public class Parse {

	
	WebDriver  driver = new FirefoxDriver();
	
	
	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
						

		Parse parse = new Parse();
		
		parse.doIt();
		

	}
	
	
	public void doIt() throws InterruptedException{

		
		//http://de.anyoption.com/Abgelaufene+bin%C3%A4re+Optionen
		
		//System.out.println("Hallo");
		
		driver.get("http://de.anyoption.com/Abgelaufene+bin%C3%A4re+Optionen");
		
		//Select select = new Select ( driver.findElement(By.id("lastLevelsForm:selectedAssetNameDisplay")) );
		
		
		
		
		WebElement dateField = driver.findElement(By.id("lastLevelsForm:from")); 
		
		dateField.clear();
		
		dateField.sendKeys("22.02.13");
		//dateField.sendKeys(Keys.DELETE);
		
		//JavascriptExecutor js = (JavascriptExecutor) driver;
		
		//js.executeScript("javascript:CP_tmpReturnFunction(2013,2,21);");
		
		
		
		WebElement element = driver.findElement(By.id("arrowDown"));
		
		element.click();		
		
		WebElement assetsList = driver.findElement(By.id("assetsList"));
		
		//System.out.println(assetsList.toString());
		
		//System.out.println(assetsList.getText());
		
		//System.out.println( assetsList.findElement(By.linkText("Vix")) );
		
		assetsList.findElement(By.linkText("Vix")).click();
		
		//driver.findElement(By.id("anchor2")).click();
		
		//Thread.sleep(1000);
		
		
		
		//driver.wait(1000);
		
		
		//driver.findElement(By.id("lastLevelsForm:button")).click();
		
		
		WebElement  webElement   =  null;
		
		
		
		for(int x = 1; x < 1000; x++){
		
			webElement = driver.findElement(By.xpath(".//*[@id='lastLevelsForm:data:tbody_element']/tr[" + x + "]/td[1]"));
			
			System.out.println("Wertname: " + webElement.getText() );
			
			
			webElement = driver.findElement(By.xpath(".//*[@id='lastLevelsForm:data:tbody_element']/tr[" + x + "]/td[2]"));
			
			System.out.println("Wert des Wertes: " + webElement.getText() );			
			
			
			webElement = driver.findElement(By.xpath(".//*[@id='lastLevelsForm:data:tbody_element']/tr[" + x + "]/td[3]"));
			
			System.out.println("Zeitpunkt: " + webElement.getText() );			
			
		} 
		
		
		return;
		
		//driver.quit();
		
		/**
		WebElement select = driver.findElement(By.id("assetsList"));
		
		List<WebElement> allOptions = select.findElements(By.className("option_type"));
		
		for (WebElement option : allOptions) {
		    System.out.println(String.format("Value is: %s", option.getAttribute("value")));
		    option.click();
		}
		**/
		
	}
	
	

}
